<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use EasyWeChat\Foundation\Application;
use DB;
class UnsetController extends Controller
{

  public $app = null;
  public function __construct(){
    $options = [
      'debug'  => true,
      'app_id' => 'wx61a5ce5230a32e92',
      'secret' => 'c04256c9ebe2c5988f26c6322e2b3623 ',
      'token'  => 'johntesting',
      // 'aes_key' => null, // 可选
      'log' => [
          'level' => 'debug',
          'file'  => '/tmp/easywechat.log', // XXX: 绝对路径！！！！
      ],
      'oauth' => [
         'scopes'   => ['snsapi_base'],
         'callback' => '/unlogin',
       ],
      'guzzle'=>[
        'timeout'=>5.0,
        'verify'=>false,
      ]
      //...
    ];
    $this->app = new Application($options);
  }
    public function unlogin(Request $req){
        $oauth = $this->app->oauth;
        $user = $oauth->user();
        $req->session()->put('user', $user);
        //return redirect('/uncenter');
				return $this->untiao($user);
    }
    public function uncenter(Request $req){

            $oauth = $this->app->oauth;
            return $oauth->redirect();
            //return redirect('unlogin');
				}

    public function unlogout(Request $req){
        $req->session()->forget('user');
        return $this->redirect('/uncenter');
    }
		public function untiao($id){

        $ids = DB::table('tbgatemember')->where('openID','=',$id['id'])->get(['did']);
        //dd($ids)
        return view('jiechubangding',['id'=>$id,'ids'=>$ids]);


        // return redirect("http://baidu.com");

		}
    public function uninset(){
        //return redirect("http://baidu.com");
        $id = $_POST['jiechu'];
        //DB::table('tbgatemember')->insert(['openID'=>$_POST['openid'],'uninset'=>$_POST['uninset']]);
        return DB::table('tbgatemember')->where('did','=',$id)->delete()?redirect('/center'):0;
        //return $_POST;
    }
    public function cat(){
          return DB::table('tbgatemember')->insert(['did'=>'post','openID'=>$_POST['data']]);
          // return $_POST['data'];
    }

}
